using System;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;

namespace UFrame.TestCode
{
    public class TestPool : MonoBehaviour
    {
        public PoolMonoMa poolMono;
        private List<GameObject> goList = new List<GameObject>();

        private FloatTimeCounter c = new FloatTimeCounter(0.1f, () => { });

        [Range(0,3)]
        public float time = 0.5f;
        
        public void TestDDD()
        {
            string poolName = "音乐";

            //测试对象池
            GameObject o = new GameObject();
            PoolMa.PrepareObj(poolName, o);

            GameObject go1 = PoolMa.SpawnObj(poolName);
            GameObject go2 = PoolMa.SpawnObj(poolName);
            GameObject go3 = PoolMa.SpawnObj(poolName);

            PoolMa.RecycleObj(poolName, go1);
            PoolMa.RecycleObj(poolName, go2);
            PoolMa.RecycleObj(poolName, go3);

            int count = PoolMa.HasCount(poolName);
            count = 3;

            if (count == 3)
            {
            }
        }

        public void Awake()
        {
            c = new FloatTimeCounter(0.1f, () =>
            {
                for (int i = 0; i < goList.Count; i++)
                {
                    PoolMa.RecycleObj("test1", goList[i]);
                }

                goList.Clear();

                for (int i = 0; i < 100; i++)
                {
                    var go = PoolMa.SpawnObj("test1");
                    go.transform.position = new Vector3(5 * Random.value, 5 * Random.value, 5 * Random.value);
                    go.SetActive(true);
                    goList.Add(go);
                }
            });
            c.isOne = false;
            
        }

        public void Start()
        {
            for (int i = 0; i < 100; i++)
            {
                var go = PoolMa.SpawnObj("test1");
                goList.Add(go);
            }
        }

        public void Update()
        {
            c.time = time;
            c.IsReachSus();
        }
    }
}